const deepClone = require("../template.js")

/** 1. 对象和数组测试 */
function testObjects() {
  console.log(
    "1.1 简单对象:",
    (() => {
      const obj = { a: 1, b: "test", c: true }
      const cloned = deepClone(obj)
      return JSON.stringify(cloned) === JSON.stringify(obj) && cloned !== obj
    })()
  )

  console.log(
    "1.2 简单数组:",
    (() => {
      const arr = [1, 2, 3, "test", true]
      const cloned = deepClone(arr)
      return JSON.stringify(cloned) === JSON.stringify(arr) && cloned !== arr
    })()
  )

  console.log(
    "1.3 空对象和空数组:",
    (() => {
      const emptyObj = {}
      const emptyArr = []
      const clonedObj = deepClone(emptyObj)
      const clonedArr = deepClone(emptyArr)
      return (
        Object.keys(clonedObj).length === 0 &&
        clonedArr.length === 0 &&
        clonedObj !== emptyObj &&
        clonedArr !== emptyArr
      )
    })()
  )

  console.log("--------------------")
}

testObjects()

module.exports = testObjects
